<?php

declare(strict_types=1);

namespace app\common\model\Order;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @mixin \think\Model
 */
class Order extends Model
{
    protected $table = 'pre_order';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    // 定义创建时间
    protected $createTime = 'createtime';

    // 定义更新时间
    protected $updateTime = false;
    use SoftDelete;

    // 软删除字段
    protected $deleteTime = 'deletetime';

    protected $append = [
        'status_text', //多张
    ];

    public function getStatusTextAttr($value, $data)
    {
        $status = $data['status'];
        $text = '';

        switch ($status) {
            case 1:
                $text = '已支付';
                break;
            case 2:
                $text = '已发货';
                break;
            case 3:
                $text = '已收货';
                break;
            case 4:
                $text = '已评价';
                break;
            case -1:
                $text = '已退货';
                break;
            case -2:
                $text = '退货中';
                break;
            case -3:
                $text = '拒绝退货';
                break;
            default:
                $text = '未知状态';
        }

        return $text;
    }
    public function address()
    {
        return $this->belongsTo('app\common\model\User\Address','addrid','id');
    }
    public function user()
    {
        return $this->belongsTo('app\common\model\User\User','userid','id');
    }
    public function express()
    {
        return $this->belongsTo('app\common\model\Product\Express','expid','id');
    }
}
